﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ornament.Messages;
using Ornament.Web;

namespace Ornament.MVCWebFrame.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }
        [Authorize]
        public ActionResult Admin()
        {
            IList<Info> listInfo =
                OrnamentContext.Current.MessageManager.Factory.InfoDao.Find(
                    OrnamentContext.Current.CurrentUser, 10, 0, MessageType.WorkList.ToString());
            ViewData["workList"] = listInfo;
            return View();
        }


        [Authorize]
        public ActionResult GetInfoItems(int pageSize, int pageIndex, string template)
        {
            try
            {
                IList<Info> infos = OrnamentContext.Current.MessageManager.Factory.InfoDao.Find(
                    OrnamentContext.Current.CurrentUser, pageSize, pageIndex);
                var result = new List<string>();
                foreach (Info info in infos)
                {
                    result.Add(info.Show(template));
                }
                return Json(result);
            }
            catch (Exception ex)
            {
                return Json(new ReturnResult(ex, true), JsonRequestBehavior.AllowGet);
            }
        }

        public ActionResult About()
        {
            return View();
        }
    }
}